package com.cat.greedyAlgorithm;

/**
*   @description https://leetcode.cn/problems/minimum-number-of-food-buckets-to-feed-the-hamsters/
*   @author 曲大人的喵
*   @create 2025/8/25 15:04
*   @since JDK17
*/

public class Solution34 {
    public int minimumBuckets(String hamsters) {
        int n = hamsters.length(), ans = 0;
        char[] s = hamsters.toCharArray();
        for (int i = 0; i < n; i++) {
            if (s[i] == 'H') {  // 仓鼠
                if (i < n - 2 && s[i + 1] == '.') {
                    ans++;
                    i++;
                } else if (i > 0 && s[i - 1] == '.') {
                    ans++;
                } else {
                    return -1;
                }
            }
        }

        return ans;
    }
}
